import store from '../store'
import Vue from 'vue'
import VueRouter from 'vue-router'
import Admin from '_views/Admin'
import Login from '_views/Login'
import NotFound from '_views/NotFound'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'admin',
    component: Admin,
    children: [
      {
        path: '/',
        redirect: '/home'
      },
      {
        path: '/home',
        name: '仪表盘',
        component: () => import('_views/Home')
      },
      {
        path: '/cataLists',
        name: '商品分类管理',
        component: () => import('_views/CataLists')
      },
      {
        path: '/itemLists',
        name: '商品列表',
        component: () => import('_views/ItemLists')
      },
      {
        path: '/itemAdd',
        name: '增加商品',
        component: () => import('_views/ItemAdd')
      },
      {
        path: '/itemUpdates',
        name: '修改商品',
        component: () => import('_views/ItemUpdate')
      },
      {
        path: '/orderGoods',
        name: '订单',
        component: () => import('_views/OrderGoods')
      },
      {
        path: '/unpayoff',
        name: '待支付',
        component: () => import('_views/UnPayoff')
      },
      {
        path: '/undelivery',
        name: '待发货',
        component: () => import('_views/UnDelivery')
      },
      {
        path: '/delivered',
        name: '已发货',
        component: () => import('_views/Delivered')
      },
      {
        path: '/user',
        name: '个人中心',
        component: () => import('_views/User')
      },
      {
        path: '/settings',
        name: '设置',
        component: () => import('_views/Settings')
      }
    ]
  } ,
    {
      path: '/login',
      nameL: '登录',
      component: Login     
    },
    {
      path: '*',
      nameL: 'notFound',
      component: NotFound
      
    }
]




const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 路由后置守卫，获得要跳转路由的name，将其存入store中
router.afterEach((to) => {
  const tab = {
    name: to.name,
    path: to.path
  }
  console.log(11);
  store.commit('base/ADD_NAV_TAB', tab)
})

export default router
